import { useTableColumnProps } from '/@/hooks/table-column/props'
import {
  useFormatDateHms,
  useFormatDateYMDHms,
  useFormatDateYYYYMMDD
} from '/@/hooks/formatter'

/**
 * 使用 useFormatDateYYYYMMDD
 * @param prop column.prop
 * @param label column.label
 * @param options tableColumn的其他属性
 * @returns tableColumn props
 */
export function useTableColumnFormatterYYYYMMDD<
  T extends Record<string, any>,
  P extends keyof T
>(prop: P, label: string, options: UseTableColumnProps<any, T, P> = {}) {
  return useTableColumnProps(prop, label, {
    ...options,
    formatter: (row: T) => useFormatDateYYYYMMDD(row[prop])
  })
}

/**
 * 使用 useFormatDateYMDHms
 * @param prop column.prop
 * @param label column.label
 * @param options tableColumn的其他属性
 * @returns tableColumn props
 */
export function useTableColumnFormatterYMDHms<
  T extends Record<string, any>,
  P extends keyof T
>(prop: P, label: string, options: UseTableColumnProps<any, T, P> = {}) {
  return useTableColumnProps(prop, label, {
    ...options,
    formatter: (row: T) => useFormatDateYMDHms(row[prop])
  })
}

/**
 * 使用 useFormatDateHms
 * @param prop column.prop
 * @param label column.label
 * @param options tableColumn的其他属性
 * @returns tableColumn props
 */
export function useTableColumnFormatterHms<
  T extends Record<string, any>,
  P extends keyof T
>(prop: P, label: string, options: UseTableColumnProps<any, T, P> = {}) {
  return useTableColumnProps(prop, label, {
    ...options,
    formatter: (row: T) => useFormatDateHms(row[prop])
  })
}
